Fix QueryPage transaction plan
authorTim Starling <tstarling@wikimedia.org>
Wed, 11 Dec 2013 00:57:00 +0000 (11:57 +1100)
committerTim Starling <tstarling@wikimedia.org>
Wed, 11 Dec 2013 00:57:00 +0000 (11:57 +1100)
The COMMIT in updateSpecialPages.php was unmatched and just logged an
error. We would like the stale results to still be presented to the user
during the hours of query execution time, so doing a DELETE in
autocommit mode before the main query starts does not seem appropriate.
And holding a master transaction open for hours, with a lock on
querycache, is certainly not the right way to do it.

So, move the DELETE to after the completion of the main query, and wrap
a transaction around the updates to querycache and querycache_info so
that the user always sees a consistent populated UI. Remove the
unmatched COMMIT from updateSpecialPages.php.

Change-Id: I27c22b96f43a1064eb17a0c6a1c56d1f4a2dff9a

includes/QueryPage.php
maintenance/updateSpecialPages.php

index ff505b1..a904c24 100644 (file)
@@ -300,8 +300,6 @@ abstract class QueryPage extends SpecialPage {
                }
 
                try {
-                       # Clear out any old cached data
-                       $dbw->delete( 'querycache', array( 'qc_type' => $this->getName() ), $fname );
                        # Do query
                        $res = $this->reallyDoQuery( $limit, false );
                        $num = false;
@@ -327,6 +325,9 @@ abstract class QueryPage extends SpecialPage {
                                                        'qc_value' => $value );
                                }
 
+                               $dbw->begin( __METHOD__ );
+                               # Clear out any old cached data
+                               $dbw->delete( 'querycache', array( 'qc_type' => $this->getName() ), $fname );
                                # Save results into the querycache table on the master
                                if ( count( $vals ) ) {
                                        $dbw->insert( 'querycache', $vals, __METHOD__ );
@@ -336,6 +337,7 @@ abstract class QueryPage extends SpecialPage {
                                $dbw->insert( 'querycache_info',
                                        array( 'qci_type' => $this->getName(), 'qci_timestamp' => $dbw->timestamp() ),
                                        $fname );
+                               $dbw->commit( __METHOD__ );
                        }
                } catch ( DBError $e ) {
                        if ( !$ignoreErrors ) {
index 3432cb2..40c6951 100644 (file)
@@ -112,9 +112,6 @@ class UpdateSpecialPages extends Maintenance {
                                                        sleep( 10 );
                                                } while ( !wfGetLB()->pingAll() );
                                                $this->output( "Reconnected\n\n" );
-                                       } else {
-                                               # Commit the results
-                                               $dbw->commit( __METHOD__ );
                                        }
                                        # Wait for the slave to catch up
                                        wfWaitForSlaves();